package academia.gui;

import java.sql.*;
import academia.persistencia.DBAcademia;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class TelaExcluir extends javax.swing.JFrame {

<<<<<<< .mine

    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement ps = null;

    /**
     * Creates new form TelaExcluir
     */

=======
    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement ps = null;

>>>>>>> .r149
    public TelaExcluir() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        cpf = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();

        jButton1.setText("jButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        cpf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cpfActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Informe o CPF:");

        jButton2.setText("Deletar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(51, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(cpf, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(49, 49, 49))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(134, 134, 134)
                .addComponent(jButton2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(87, 87, 87)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(30, 30, 30))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cpfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cpfActionPerformed
    }//GEN-LAST:event_cpfActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
<<<<<<< .mine
        conn = DBAcademia.ConnectDB();
        if (cpf.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Campo obrigatorio\nTente novamente", "Erro", JOptionPane.ERROR_MESSAGE);
        }
        try {
            String sql = "DELETE FROM Pessoa WHERE Cpf='" + cpf.getText() + "'";
            ps = conn.prepareStatement(sql);

            ps.executeUpdate();

            JOptionPane.showMessageDialog(null, "Excluido.");
            new TelaGerente().setVisible(true);
            this.dispose();


            //conn.commit();


        } catch (SQLException a) {
            a.printStackTrace();
            JOptionPane.showMessageDialog(null, a);
        } finally {
            try {
                
                ps.close();
            } catch (SQLException ex) {
                Logger.getLogger(TelaExcluir.class.getName()).log(Level.SEVERE, null, ex);
            }

=======
        conn = DBAcademia.ConnectDB();
        if (cpf.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Campo obrigatorio\nTente novamente", "Erro", JOptionPane.ERROR_MESSAGE);
        }
        try {
            String sql = "DELETE from Pessoa where CPF=" + cpf.getText() + ";";
            ps = conn.prepareStatement(sql);
            JOptionPane.showMessageDialog(null, "Cadastro efetuado com Sucesso.");
        } catch (SQLException a) {
            JOptionPane.showMessageDialog(null, a);
        } finally {
            try {
                rs.close();
                ps.close();
            } catch (SQLException ex) {
                Logger.getLogger(TelaExcluir.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
>>>>>>> .r149
    }//GEN-LAST:event_jButton2ActionPerformed
<<<<<<< .mine


        /**
         * @param args the command line arguments
         */
    }

=======
>>>>>>> .r149
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField cpf;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
